import Filter from '../../components/Business/MerchantsFilter'
import Grid from '../../components/Business/MerchantsGrid'
import React,{ Component } from "react";
import {Breadcrumb, Icon, Pagination } from 'antd'
import { Link } from 'react-router-dom'
import API from '../../api/business/business'
class PersonList extends Component{
    state = {
        create: false,
        list: [],
        query: {},
        pagination: {
            page: 1,
            pageSize: 10
        },
        recordCount: null
    }
	componentDidMount(){
        this.doSearch()
	}
    doSearch = (query) => {
        let clear = typeof query === 'object' && query.hasOwnProperty('clear') ? query.clear : false
	    API.doSearch(clear ? {} : Object.assign(this.state.query, query)).then(res => {
            this.setState({list: res.data.listData, recordCount: parseInt(res.data.recordCount, 10)})
        })
    }
    onChangePage = (e) => {
        this.doSearch({page: e, pageSize: this.state.pagination.pageSize})
    }
    onShowSizeChange = (current, pageSize) => {
        console.log(current, pageSize)
        this.doSearch({page: current, pageSize: pageSize})

    }
    onCreate = () => {
        console.log(11)
        this.setState({create: true})
    }
    handleOk = () => {
        this.setState({create: false})
    }
	render(){
		return(
			<div>
				<div className="common-bread">
                    <Breadcrumb style={{ margin: '12px 0' }}>
                        <Breadcrumb.Item>
                            <Link to={`/dashboard`}><Icon type="home" /></Link>
                        </Breadcrumb.Item>
                        <Breadcrumb.Item>商家管理</Breadcrumb.Item>
                        <Breadcrumb.Item>商家列表</Breadcrumb.Item>
                    </Breadcrumb>
				</div>
                <Filter doSearch={this.doSearch} onCreate={this.onCreate}/>
                <div>
                    <Grid
                        className="idle-grid"
                        list={this.state.list}
                    />
                    <Pagination
                        style={{margin: '30px 0 0 0'}}
                        showQuickJumper
                        showSizeChanger
                        defaultCurrent={1}
                        total={this.state.recordCount}
                        showTotal={total => `共 ${total} 条`}
                        onShowSizeChange={this.onShowSizeChange}
                        onChange={this.onChangePage} />
				</div>
			</div>
		)
	}
}

export default PersonList;